﻿// JScript 文件
function Ajax_GetXMLHttpRequest() {
    if (window.XMLHttpRequest) {
	    return new XMLHttpRequest();
    } else {
	    if (window.Ajax_XMLHttpRequestProgID) {
		    return new ActiveXObject(window.Ajax_XMLHttpRequestProgID);
	    } else {
		    var progIDs = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		    for (var i = 0; i < progIDs.length; ++i) {
			    var progID = progIDs[i];
			    try {
				    var x = new ActiveXObject(progID);
				    window.Ajax_XMLHttpRequestProgID = progID;
				    return x;
			    } catch (e) {
			    }
		    }
	    }
    }
    return null;
}
function Ajax_CallBack(url,args,processStart,clientCallBack,processEnd){
    var x = Ajax_GetXMLHttpRequest();
    var result = null;
    if (!x) {
        result = { "value":null, "error": "NOXMLHTTP"};
        return result;
    }
    x.open("POST",url,true);
    x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=gb2312");
    //
    if(processStart != null)
        processStart();
    if(clientCallBack){
        x.onreadystatechange = function(){
            if(x.readyState != 4)
                return;
            result = x.responseText;
            clientCallBack(result);
            if(processEnd != null)
                processEnd();
        }
    }
    var arg = "AjaxCallBack=true";
    arg += args;
    x.send(arg);
    delete x;
    return result;
}
function AjaxCallWithDefaultPrc(url,args,callback){
    Ajax_CallBack(url,args,prcStart,callback,prcEnd);
}